const express = require('express');
const router = express.Router();

// const DB = require('../utility/db/async-db2');
const DB = require('../utility/db/asysc_db4');
// test DB 
let myDB = new DB('hs_cms_db');
// async function getAdmins(){
//   let rows = await myDB.select('*', 'hs_admin', '');
//   console.log(rows);
// }
// getAdmins();

// 1.导入 工具包
const { findALLData } = require('../utility/db/async-db');

router.get('/', async function(req, res) {
  // 查询
  // let data = await findALLData('hs_admin');

  let data = await myDB.select('aname,aid,apwd', 'hs_admin', 'where aid in (select max(aid) from hs_admin)');
  console.log(data);
  console.log('接收到的数据:', data.data[0].aid);
  let max_aid = data.data[0].aid;
  let new_aid = (parseInt(max_aid) + 1).toString();
  let res1 = await myDB.insert('hs_admin', 'aid,aname,apwd,anname', `'${new_aid}','admin5','12345678','今天是1月8日'`);
  console.log('插入数据:', res1);
  data = await myDB.select('*', 'hs_admin', '');
  console.log('再次接收到的数据:', data);
  // let res2 = await myDB.update('hs_admin', 'apwd', 'helloworld', `where aname = 'admin2'`);
  // let res3 = await myDB.delete('hs_admin', `where id = 3`);
  
  res.send({code: 200, data: data});
});




module.exports = router;
